/*
 * @Description: 基于Arduino的红外控制器项目
 * @Author: diyhome
 * @Gitee: https://gitee.com/jingjiangxueyuan_hmqs
 * @Date: 2019-10-11 21:17:57
 * @LastEditors: diyhome
 * @LastEditTime: 2019-10-12 22:37:50
 */
#include <IRremote.h>

#define RECV_VCC 10
#define RECV_GND 11

#define SEND_GND 5

int OUTPUT_Port[] = {RECV_GND, RECV_VCC, SEND_GND};

int RECV_PIN = 9;

IRrecv irrecv(RECV_PIN);

IRsend IRS;

decode_results results;

/**
 * @description: 读取红外HEX编码
 */
void ReadHex();
void SendHex();

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();

  // pinMode(RECV_VCC, OUTPUT);
  // pinMode(RECV_GND, OUTPUT);

  for (int i = 0; i < sizeof(OUTPUT_Port); i++) pinMode(i, OUTPUT);

  digitalWrite(RECV_VCC, 1);
  digitalWrite(RECV_GND, 0);
  digitalWrite(SEND_GND, 0);
}

void loop() {
  if(Serial.available() > 0)
  {
    char c = Serial.read();
    Serial.println(c);
    IRS.sendNEC(c,32);
  }
}

void ReadHex()
{
    if (irrecv.decode(&results)) {
      Serial.println(results.value);
      irrecv.resume();
    }
}